#ifndef _AT32_BOARD_H_
#define _AT32_BOARD_H_
#include "at32f4xx.h"
#include <stdlib.h>
#include <stdio.h>
#include "at32f4xx.h"
#include "FreeRTOS.h"
#include "task.h"

#define __DEBUG__    //宏定义打印开关

#ifdef __DEBUG__
    #define DBUG_SHOW(...) printf(__VA_ARGS__)  //宏打印函数定义
#else
    #define DBUG_SHOW(...)
#endif

enum board_button
{
	KEY_0_SHORT,
	KEY_1_SHORT,
	KEY_2_SHORT,
	KEY_3_SHORT,
	KEY_4_SHORT,
	KEY_5_SHORT,
	KEY_0_LONG,
	KEY_1_LONG,
	KEY_2_LONG,
	KEY_3_LONG,
	KEY_4_LONG,
	KEY_5_LONG,
	KEY_MAX,
};

typedef struct __attribute__((packed))
{
	uint32_t press_tick;
	uint8_t long_trigger;
}button_state_t;

typedef enum
{
	ENCODRE_B,
	ENCODRE_C,
	ENCODRE_MAX
}encoder_id_t;

typedef enum
{
	ROTATION_IDLE,
	ROTATION_SLOW,
	ROTATION_FAST
}rotation_speed_t;

typedef struct __attribute__((packed))
{
	uint8_t prev_state;
	uint8_t curr_state;
	TickType_t last_rotation_tick;
	uint32_t rotation_period;
	rotation_speed_t speed;
	int8_t direction;
	uint8_t detect_ok;
}encoder_state_t;

typedef encoder_state_t (*encoder_state_ptr)[ENCODRE_MAX];

void button_task_Function(void *pvParameters);


void usart1_init(void);
void button_pin_init(void);

#endif
